########################
## tool set
########################
CC = i586-elf-gcc
CCFLAGS = -ffreestanding -nostdlib -fno-builtin -fno-exceptions -c
CXXFLAGS = -nostdlib -fno-builtin -fno-rtti -fno-exceptions -c

AS = nasm
ASFLAGS = -f elf

LD = i586-elf-ld
LDFLAGS = -T link.ld

COPY = cp $@ ./disk/$@

DISK = mkisofs -R -b grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -boot-info-table -o ./OS.iso ./disk

########################
## outputs
########################
PROGS = OS.OS
OS_OBJS = 	\
			source/main.o		\
			source/entry.o		\
			source/textscreen.o \
			source/stdio.o		

########################
## targets
########################
all: $(PROGS)
	@$(DISK)
	
OS.OS: $(OS_OBJS)
	@echo Linking
	@$(LD) $(LDFLAGS) -o $@ $(OS_OBJS)
	@$(COPY)

clean:
	@rm $(OS_OBJS)

########################
## rules
########################
.cpp.o:
	@echo making $@
	@$(CC) $(CXXFLAGS) -o $@ $<

.c.o:
	@echo making $@
	@$(CC) $(CCFLAGS) -o $@ $<
	
.s.o:
	@echo making $@
	@$(AS) $(ASFLAGS) -o $@ $<




